<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JhERP-首页</title>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
        }

        header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            background-color: #333;
            color: #fff;
            padding: 10px 20px;
            z-index: 1000;
        }

        nav ul {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        nav ul li {
            position: relative;
            color: #fff;
            cursor: pointer;
            padding: 0 15px;
        }

        nav ul li ul {
            display: none;
            position: absolute;
            background-color: #333;
            padding: 10px;
            box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
            flex-direction: column;
            align-items: flex-start;
            top: 100%;
            left: 0;
            width: 200px;
        }

        nav ul li:hover ul {
            display: block;
        }

        nav ul li ul li {
            display: block;
            color: #fff;
            padding: 5px 0;
            cursor: pointer;
            width: 100%;
            text-align: left;
        }

        nav ul li ul li:hover {
            background-color: #555;
        }

        iframe {
            width: 100%;
            height: calc(100vh - 80px);
            border: 0;
        }

        footer {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            background-color: #333;
            color: #fff;
            padding: 10px 20px;
        }

        .content {
            margin-top: 40px;
            padding: 20px;
        }

        .menu-info {
            display: flex;
            align-items: center;
        }

        .menu-info img {
            margin-right: 10px;
            width: 50px;
            height: auto;
        }

        #logout-btn {
            margin-left: auto;
        }

        @media only screen and (max-width: 600px) {
    /* 修改header样式 */
    header {
        padding: 5px 10px;
    }

    nav ul li {
        padding: 0 10px;
    }

    nav ul li ul {
        width: 150px;
    }

    /* 修改iframe样式 */
    iframe {
        height: calc(100vh - 50px);
    }

    /* 修改footer样式 */
    footer {
        padding: 5px 10px;
    }

    .menu-info img {
        width: 40px;
    }
}
    </style>
</head>
<body>
<header>
    <nav>
        <ul>
            <div class="menu-info">
                <img src="{{ url_for('static', filename='logo.png') }}" alt="Logo">
            </div>
            <li class="menu-item">客户管理
                <ul class="submenu">
                    <li onclick="loadContent('/list_customer')" class="menu-item">客户列表</li>
                    <li onclick="loadContent('/add_customer')" class="menu-item">添加客户</li>
                </ul>
            </li>
            <li class="menu-item">产品管理
                <ul class="submenu">
                    <li onclick="loadContent('/product_list')" class="menu-item">产品列表</li>
                    <li onclick="loadContent('/add_product')" class="menu-item">添加产品</li>
                    <li onclick="loadContent('/class_list')" class="menu-item">类别管理</li>
                </ul>
            </li>
            <li class="menu-item">入库单管理
                <ul class="submenu">
                    <li onclick="loadContent('/warehousing_entry_list')" class="menu-item">入库单列表</li>
                    <li onclick="loadContent('/warehousing_entry_add')" class="menu-item">录入入库单</li>
                </ul>
            </li>
            <li class="menu-item">仓库管理
                <ul class="submenu">
                    <li onclick="loadContent('/inventory')" class="menu-item">库存列表</li>
                </ul>
            </li>

            <li class="menu-item">出库单管理
                <ul class="submenu">
                    <li onclick="loadContent('/outbound_order_list')" class="menu-item">出库单列表</li>
                    <li onclick="loadContent('/outbound_order_add')" class="menu-item">录入出库单</li>
                </ul>
            </li>
            <li class="menu-item" id="logout-btn">注销</li>
        </ul>
    </nav>
</header>

<div class="content">
    <iframe id="contentFrame" src="/product_list" frameborder="0"></iframe>
</div>

<footer>
    &copy; 2024 JhERP
</footer>

<script>
    function loadContent(url) {
        document.getElementById('contentFrame').src = url;
    }

    // 获取注销按钮
    var logoutBtn = document.getElementById("logout-btn");

    // 给注销按钮添加点击事件
    logoutBtn.addEventListener("click", function(){
        // 发送POST请求到服务器以注销用户
        fetch('/logout', { method: 'POST' })
            .then(response => {
                if (response.redirected) {
                    // 重定向到登录页面
                    window.location.href = response.url;
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    });

    let timeout;

    function startLogoutTimer() {
        timeout = setTimeout(logoutUser, 1800000); // 30分钟后执行注销操作
    }

    function resetLogoutTimer() {
        clearTimeout(timeout); // 重置计时器
        startLogoutTimer(); // 重新开始计时
    }

    function logoutUser() {
        fetch('/logout', { method: 'POST' })
            .then(response => {
                if (response.redirected) {
                    window.location.href = response.url; // 重定向到登录页面
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    }

    // 监听用户操作事件
    document.addEventListener("mousemove", resetLogoutTimer);
    document.addEventListener("keypress", resetLogoutTimer);

    // 页面加载后开始计时
    document.addEventListener("DOMContentLoaded", startLogoutTimer);
</script>
</body>
</html>
